package com.rentong;

import com.rentong.config.SpecialConfig;
import com.zaxxer.hikari.HikariDataSource;
import lombok.extern.slf4j.Slf4j;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.boot.web.servlet.MultipartConfigFactory;
import org.springframework.context.annotation.Bean;

import javax.servlet.MultipartConfigElement;
import javax.sql.DataSource;
@Slf4j
@SpringBootApplication
@EnableConfigurationProperties
@MapperScan("com.rentong.**.dao")
public class BackApplication {
    public static void main(String[] args)  {
        SpringApplication.run(BackApplication.class, args);
        System.out.println("============= Back Start Success =============");
    }

    @Bean
    @ConfigurationProperties(prefix = "spring.datasource.hikari")
    public DataSource dataSource() {
        return new HikariDataSource();
    }

    @Bean
    @ConfigurationProperties(prefix = "special")
    public SpecialConfig specialConfig(){
        return new SpecialConfig();
    }

    //防止图片限制为1兆
    @Bean
    public MultipartConfigElement multipartConfigElement() {
        MultipartConfigFactory factory = new MultipartConfigFactory();
        factory.setMaxRequestSize("100MB");
        factory.setMaxFileSize("100MB");
        return factory.createMultipartConfig();
    }



}
